package com.wu.findcontinuoussequence;

import java.util.ArrayList;

/**
 * 和为S的连续正数序列
 * @author lynn
 * @date 2020/9/2 - 12:18
 */
public class Solution {
    public static ArrayList<ArrayList<Integer>> FindContinuousSequence(int sum) {

        ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
        for (int i = 1; i < sum; i++) {
            int cur = 0;
            int val = i;
            while (cur < sum) {
                cur += val;
                val++;
            }
            if (cur == sum) {
                ArrayList<Integer> list = new ArrayList<Integer>();
                for (int k = i; k < val; k++) {
                    list.add(k);
                }
                result.add(list);
            }
        }
        return result;
    }

    public static void main(String[] args) {
        ArrayList<ArrayList<Integer>> arrayLists = FindContinuousSequence(15);
        arrayLists.stream().forEach(System.out::println);
    }
}